SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO


alter  TRIGGER dbo.tr_person ON dbo.person 
FOR INSERT
AS
BEGIN
	set nocount on

	declare 
			@embg varchar(20),
			@first_name nvarchar(30),
			@last_name nvarchar(50),
			@username nvarchar(30),
			@password nvarchar(30),
			@address nvarchar(50),
			@city nvarchar(30),   
			@birth_date datetime,
			@birth_place nvarchar(30)

	--set @msg = dbo.fn_TranslateMessage(80162)

	declare emi_cursor cursor local fast_forward for
		select 
			embg,first_name,last_name,username,password,address,city,birth_date,birth_place
		from inserted 

	open emi_cursor	

	fetch next from emi_cursor into 
		@embg,@first_name,@last_name,@username,@password,@address,@city,@birth_date,@birth_place
	while @@fetch_status = 0
		begin
			exec add_new_personnel @embg,@first_name,@last_name,@username,@password,@address,@city,@birth_date,@birth_place,
														 null, null, null

      if @@error <> 0
      begin
        raiserror('Se pojavi greska', 16, 1)   
        return
      end

			fetch next from emi_cursor into 
				@embg,@first_name,@last_name,@username,@password,@address,@city,@birth_date,@birth_place

		end
	deallocate emi_cursor

END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

